<template>
  <!--  物料申请表 -->
  <div id="adduser">
    <el-dialog  :title="datas.account?'修改申请':'申请采购'" :visible.sync="dialogVisible" width="45%" top="3vh" :close-on-click-modal='false'>
      <div style="width:90%;margin: 0 auto;padding-bottom:20px;" v-loading="loading">
        <caigou :act="1"></caigou>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>物品名称</p>
          <el-input style='width:75%;' type="text" placeholder="请输入" v-model="datas.name" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>类型</p>
          <el-select  style="width:75%;border:none;" class="pboxc1" v-model="datas.typeId" clearable  placeholder="请选择">
            <el-option v-for='item in $store.state.user.leidata' :key='item.id' :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>数量</p>
          <el-input style='width:75%;' type="number" placeholder="请输入" v-model="datas.amount" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>单价</p>
          <el-input style='width:75%;' type="number" placeholder="请输入" v-model="datas.price" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>型号</p>
          <el-input style='width:75%;' type="text" placeholder="请输入" v-model="datas.model" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>尺寸</p>
          <el-input style='width:75%;' type="text" placeholder="请输入" v-model="datas.size" clearable></el-input>
        </div>

<!--        <div style="margin-top:10px;" class="tabbox">-->
<!--          <p style=""><a style="color:red;"> </a>供应商</p>-->
<!--          <el-input style='width:75%;' type="text" placeholder="请输入" v-model="datas.provider" clearable></el-input>-->
<!--        </div>-->

        <div style="margin-top:10px;height:100px" class="tabbox">
          <p style=""><a style="color:red;"></a>物品备注</p>
          <el-input type="textarea" style='width:75%;'
                    :autosize="{ minRows: 4, maxRows: 4}"
                    placeholder="请输入内容"
                    v-model="datas.remarks" clearable>
          </el-input>
        </div>

        <div style="margin-top:10px;height:100px" class="tabbox">
          <p style=""><a style="color:red;">* </a>申请原因</p>
          <el-input type="textarea" style='width:75%;'
                    :autosize="{ minRows:4,maxRows:4}"
                    placeholder="请输入内容"
                    v-model="datas.purpose" clearable>
          </el-input>
        </div>

      </div>
      <div style="width:100%;height:40px;margin-top:20px;">
        <div style="width:170px;margin: 0 auto;">
          <el-button type="danger" @click="Negate();$parent.git_act()" >取 消</el-button>
          <el-button type="primary" @click="gitact" style='float:right;'>确 定</el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>
<script>
  import caigou from '@/components/MES/steps/caigou.vue'
  import { purchasecreate } from '@/api_bast/decla_man.js'
  export default {
    name: 'decla_shen',
    components:{caigou},
    computed:{},
    data() {
      return {
        loading:false,
        dialogVisible:false,
        datas:{
          createdBy:'',//      创建人id 0
          createdTime:'',//     创建时间 0
          name:'',//          申请采购的物品名称
          typeId:'',//         类型
          amount:'',// ;       数量
          price:'',//单价
          model:'',// ;        型号
          size:'',// ;         尺寸
          provider:'',// ;     供应商
          sku:'',// ;     如果仓库中有该物品就填，没有就空着，后台自动生成 0
          remarks:'',// ;      备注
          deciml:'',//   总价 0
          purpose:'',// ;      采购原因
        },
        // numdata:{},//物料信息
      }
    },
    props:{
      edit:Number
    },
    methods: {
      panertfn(item){
        if(this.edit==1){
          this.datas=item;
        }else{
          this.qin();
          if(item.name){
            this.datas=item;
            // console.log(this.datas);
          }
        }
        this.Negate();
      },
      Negate(){this.dialogVisible = !this.dialogVisible},//显隐取反
      qin(){//清除数据方法
        this.datas = {
          createdBy:'',//      创建人id
          createdTime:'',//    创建时间
          name:'',//           申请采购的物品名称
          typeId:'',//         型号
          amount:'',// ;       数量
          price:'',//          单价
          model:'',// ;        型号
          size:'',// ;         尺寸
          provider:'',// ;     供应商
          remarks:'',// ;      备注
          purpose:'',// ;      采购原因
          sku:'',// ;          如果仓库中有该物品就填，没有就空着，后台自动生成
          deciml:'',//         总价 0
        }
      },
      gitact(){//提交数据
        if(this.isNull(this.datas.name)){this.$message({message: '请输入 物品名称',type: 'error'});return false}
        if(this.isNull(this.datas.typeId)){this.$message({message: '请选择 类型',type: 'error'});return false}
        if(this.isNull(this.datas.amount)){this.$message({message: '请输入申请数量',type: 'error'});return false}
        if(this.datas.amount<=0){this.$message({message: '数量 必须大于零',type: 'error'});return false}
        if(this.isNull(this.datas.price)){this.$message({message: '请输入 单价',type: 'error'});return false}
        if(this.datas.price<=0){this.$message({message: '单价 必须大于零',type: 'error'});return false}
        if(this.isNull(this.datas.model)){this.$message({message: '请输入 型号',type: 'error'});return false}
        if(this.isNull(this.datas.size)){this.$message({message: '请输入 尺寸',type: 'error'});return false}
        // if(this.isNull(this.datas.provider)){this.$message({message: '请输入 供应商',type: 'error'});return false}
        if(this.isNull(this.datas.purpose)){this.$message({message: '请输入 申请原因',type: 'error'});return false}
        this.datas.createdBy = this.json_object(this.resData()).id;
        this.datas.deciml = Number(this.datas.amount) * Number(this.datas.price);
        this.loading=true;
        purchasecreate(this.edit,this.datas).then(response => {
          this.loading = false;
          if(response.code==200){
            this.qin();
            this.$notify.success({title: '请求已提交',message: response.message});
            this.Negate();
            this.$parent.git_act();
            window.setTimeout(()=>{
              this.qgd();
            },1000);
          }
        })
      },
      qgd(){
        this.$confirm('申请表单已经提交，是否下载请购单？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

        }).catch(() => {});
      },
    },
    mounted() {
      // this.$parent.qin();//调用父组件方法
    }
  }
</script>

<style scoped>
  .min{
    font-weight: bold;
  }
  .sp1{
    float: left;
  }
  .sp2{
    float: right;
  }
  .tabbox{
    width:100%;
    height:40px;
    line-height: 30px;
    margin-top:23px;
  }
  .tabbox p{
    font-size:14px;
    font-weight: bold;
    color:#000000;
    width:15%;
    text-align:right;
    margin-right:20px;
    float:left;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    font-family:Source Han Sans CN;
  }
</style>
